package com.glq1218.authentication.controller;

import com.glq1218.authentication.dto.AuthenticationDTO;
import com.glq1218.authentication.dto.RegisterDTO;
import com.glq1218.authentication.service.AuthenticationService;
import com.glq1218.authentication.vo.AuthenticationVO;
import com.glq1218.common.model.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证控制器
 *
 * @author glq1218
 */
@Tag(name = "认证接口", description = "用户注册和认证")
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthenticationController {
    private final AuthenticationService authenticationService;

    @PostMapping("/authenticate")
    @Operation(summary = "认证", description = "认证用户")
    public Result<AuthenticationVO> authenticate(@RequestBody AuthenticationDTO authenticationDTO) {
        return Result.ok(authenticationService.authenticate(authenticationDTO));
    }

    @PostMapping("/register")
    @Operation(summary = "注册", description = "注册用户")
    public Result<?> register(@RequestBody RegisterDTO registerDTO) {
        return Result.ok(authenticationService.register(registerDTO));
    }
}
